package com
{
	import com.*;
	import com.Engine.*;
	import com.Home.*;
	import com.Packet.*;
	import com.UI.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.utils.*;
	import flash.utils.Timer;
	
	import gs.*;
	import gs.easing.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.plaf.basic.frame.BasicFrameTitleBarBG;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;

	public class SceneMain extends SceneBase
	{
		//[Embed(source="loading_progress.png")]
		//private var progress:Class;

		public function SceneMain()
		{
			super();
			setDirection();
		}
		public static var _effect_in_battle:int = 100;
		public static var _effect_team_leader:int = 200;
		private static var _instance:* = null;
		public static function getInstance():SceneMain
		{
			if(_instance == null)
				_instance = new SceneMain();
			return _instance;
		}
		private function setDirection():void
		{
			/*Directions.Stop=0;
			Directions.Down = 1;
			Directions.LeftDown = 5;
			Directions.Left = 2;
			Directions.LeftUp = 7;
			Directions.Up = 4;
			Directions.RightUp = 8;
			Directions.Right = 3;
			Directions.RightDown = 6;*/
			
			Directions.StopLeft=2;
			Directions.StopRight=3;
			Directions.Down = 2;
			Directions.LeftDown = 2;
			Directions.Left = 2;
			Directions.LeftUp = 2;
			Directions.Up = 3;
			Directions.RightUp = 3;
			Directions.Right = 3;
			Directions.RightDown = 3;
			
		}

		public function jumpMap(mapId:uint,lineId:uint,type:int,ownerId:int,mapX:uint,mapY:uint):void
		{
			Client.getInstance().sendPacketLogic(9,[mapId,lineId,type,ownerId,mapX,mapY]);
		}
		//protected var _loaderChar:Loader;
		override public function startup():void
		{
			super.startup();
		}
		
		override public function onClickObject(obj:ObjectBase):void
		{
			if(obj!=null)
			{
				var npc:ObjectCharNPC = obj as ObjectCharNPC;
				if(obj is ObjectCharNPC)
				{
					Client.getInstance().sendPacketLogic(900,[int(obj.userObject.npc_id)]);
					FrameNPCDialog._currentCharNpc = npc;
					if(FrameNPCDialog._currentCharNpc.getPos().x > CharInfo.objSelf.getPos().x)
						FrameNPCDialog._currentCharNpc.direction = Directions.Left;
					else
						FrameNPCDialog._currentCharNpc.direction = Directions.Right;
				}
				
				if(obj is ObjectCharPlayer && !(obj is ObjectCharLover))
				{
					FrameClickMapChar.show(obj as ObjectCharPlayer);
				}
				
				if(obj is ObjectCharLover)
				{
					FrameClickMapChar.show((obj as ObjectCharLover).followTarget as ObjectCharPlayer);
				}
				
				if(obj is ObjectCharPet)
				{
					FrameClickMapChar.show((obj as ObjectCharPet).followTarget as ObjectCharPlayer);
				}
				if(obj is ObjectHomeBuilding)
				{
					Home.onClickBuildingHome(obj as ObjectHomeBuilding);
				}
				//	FrameBuildingHome.show();
			}
		}
		//static public var _arrayFilters:Array = new Array(new GlowFilter(0xff0000, 0, 50, 50, 15));
		public function enterEffect():void
		{
			this.alpha = 0.1;
			TweenLite.to(this, 0.5, {autoAlpha:1.0});
			
			//this.filters = _arrayFilters;
		
		}
		
		private static var isShake:Boolean = false;  
		public static function shake(dis:DisplayObject,times:uint = 2,offset:uint = 4,speed:uint = 20):void 
		{  
			if(isShake) 
			{  
				return;  
			}  
			isShake = true;  
			var point:Point = new Point(dis.x,dis.y);  
			var offsetXYArray:Array = [0,0];  
			var num:int = 0;  
			var u:int = setInterval(function():void 
			{  
				offsetXYArray[num%2] = (num++)%4<2 ?0:offset;  
				if(num>(times*4 + 1))
				{  
					clearInterval(u);  
					num = 0;  
					isShake = false;  
				}  
				dis.x = offsetXYArray[0] + point.x;  
				dis.y = offsetXYArray[1] + point.y;  
			},speed);  
		} 
		
		public function showAllPlayers():void
		{
			for each(var obj:ObjectBase in _allObjects)
			{
				obj.updateVisible();
				/*if(obj is ObjectChar)
				{
					if(SceneBase.showAllPlayer == SceneBase.ShowAll)
					{
						obj.visible = true;
						continue;
					}
					if(SceneBase.showAllPlayer == SceneBase.ShowAllNPCPlayerSelf)
					{
						if(obj is ObjectCharLover)
						{
							obj.visible = false;
							continue;
						}
						if(obj is ObjectCharPet)
						{
							obj.visible = false;
							continue;
						}
						obj.visible = true;
						continue;
					}
					if(SceneBase.showAllPlayer == SceneBase.ShowAllNPCSelf)
					{
						if(obj is ObjectCharLover)
						{
							obj.visible = false;
							continue;
						}
						if(obj is ObjectCharPet)
						{
							obj.visible = false;
							continue;
						}
						if(obj is ObjectCharPlayer)
						{
							obj.visible = false;
							continue;
						}
						obj.visible = true;
						continue;
					}
					if(SceneBase.showAllPlayer == SceneBase.ShowAllSelf)
					{
						if(obj != CharInfo.objSelf)
						{
							obj.visible = false;
							continue;
						}
						obj.visible = true;
						continue;
					}
					if(obj != CharInfo.objSelf)
					{
						if(obj is ObjectCharLover)
						{
							obj.visible = show;
							continue;
						}
						if(obj is ObjectCharPet)
						{
							obj.visible = show;
							continue;
						}
						//if(obj is ObjectCharLover)
						if(obj._renderBitmap != null)
							obj._renderBitmap.visible = show;
					}
				}*/
			}
			//CharInfo.objSelf._renderBitmap.visible = true;
		}
		override public function onMapLoaded():void
		{
			if(PanelMain.getInstance().isInBattle)
			{
				SceneBattle.getInstance().updateBackground(this);
			}
			SceneMain.getInstance().checkNPCDialogTarget();
			PanelMainHelp.getInstance().updateMapInfo();
		}
		override public function onBuildAllObject():void
		{
			super.onBuildAllObject();
			if(Home.isInHome())
			{
				Home.updateHomeBuildings();
			}
			if(this.objectClick == null)
				objectClick = createClick(Engine.assetMapNpcPath + "npc_click.swf","npc_click.swf",new Point(0,0));
			
			SceneMain.updateNpcTaskEffect();
			
			if(PanelMain.getInstance().isInBattle)
			{
				SceneBattle.getInstance().updateBackground(this);
			}
		}
		
		override protected function render(e:Event):Boolean
		{
			if(FrameFullScreenEffect.isShowing())
				FrameFullScreenEffect._frame.renderEffects();
			return super.render(e);
		}
		
		private var _mouseDownTime:int = 0;
		override protected function onMouseDown(e:MouseEvent):void
		{
			_mouseDownTime = Engine.Timer;
		}
		override protected function onMouseUp(e:MouseEvent):void
		{
			if(Engine.Timer - _mouseDownTime > 10*1000)
			{
				var objMapCSV:Object = Client.getInstance().GetMapCSV(CharInfo.mapId);
				if(objMapCSV != null && CharInfo.objSelf != null)
					CharInfo.objSelf.setPos(objMapCSV.base_x,objMapCSV.base_y);
			}
		}
		
		public static const 	EFFECT_ID_ACCEPTABLE:uint = 3000000;
		public static const 	EFFECT_ID_COMPLETABLE:uint = 3000001;
		public static function updateNpcTaskEffect():void
		{
			var arrayAcceptable:Array = FrameTask.getAcceptableTasks();
			
			var arrayAcceptableNPC:Array = [];
			var obj:Object = null;
			for each(obj in arrayAcceptable)
			{
				if(int(obj.accepte_map_id) == CharInfo.mapId)
					arrayAcceptableNPC.push(int(obj.accepte_npc_id));
			}
			var arrayCompletedNPC:Array = [];
			for each(obj in CharInfo.m_arTasks)
			{
				if(obj.task_step == obj.task_step_size)
				{
					if(int(obj.task_goals[0].goal_map_id) == CharInfo.mapId)
						arrayCompletedNPC.push(int(obj.task_goals[0].goal_npc_id));
				}
			}
			var allObjects:Array = SceneMain.getInstance().getAllObjects()
			for each(var objBase:ObjectBase in allObjects)
			{
				if(objBase is ObjectCharNPC)
				{
					//objBase.removeEffect(EFFECT_ID_ACCEPTABLE);
					//objBase.removeEffect(EFFECT_ID_COMPLETABLE);
					if(arrayAcceptableNPC.indexOf((objBase as ObjectCharNPC).npcId) != -1)
						//objBase.addEffect(EFFECT_ID_ACCEPTABLE);
						addEffect(objBase,EFFECT_ID_ACCEPTABLE,true,false);
					else
						objBase.removeEffect(EFFECT_ID_ACCEPTABLE);
					
					if(arrayCompletedNPC.indexOf((objBase as ObjectCharNPC).npcId) != -1)
						//objBase.addEffect(EFFECT_ID_COMPLETABLE);
						addEffect(objBase,EFFECT_ID_COMPLETABLE,true,false);
					else
						objBase.removeEffect(EFFECT_ID_COMPLETABLE);
				}
			}

		}
		public static function addEffect(dest:ObjectBase,effect_id:int,bTop:Boolean = false,bRemoveAtEnd:Boolean = true,bBackward:Boolean = false):void
		{
			if(dest == null)
				return;
			var mc_effect:MovieClip = Client.getEffectElement("mc_effect_" + effect_id) as MovieClip;
			if(mc_effect == null)
				return;
			dest.addEffect(effect_id,mc_effect,bTop,bRemoveAtEnd,bBackward);
		}
		public static function removeEffect(dest:ObjectChar,effect_id:int):void
		{
			dest.removeEffect(effect_id);
		}
		
		public static function phEnterMap_6(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phEnterMap_6", msg);
			var index:int = 0;
			var count:int = msg[index++];
			for(var i:int = 0; i != count; i++)
			{
				var obj:Object = new Object();
				obj.m_nCharId = msg[index++];
				obj.m_nRace = msg[index++];
				obj.m_nGender = msg[index++];
				obj.title_id = msg[index++];
				obj.title_name = msg[index++];
				obj.m_szCharName = msg[index++];
				obj.m_nLevel = msg[index++];
				obj.IsInBattle = msg[index++];
				obj.IsInMining = msg[index++];
				obj.equip_count = msg[index++];
				obj.equip_image0 = msg[index++];
				obj.equip_image1 = msg[index++];
				obj.equip_image2 = msg[index++];
				obj.equip_image3 = msg[index++];
				obj.equip_image4 = msg[index++];
				obj.equip_image5 = msg[index++];
				obj.m_nImageId = msg[index++];
				obj.map_id = msg[index++];
				obj.line_id = msg[index++];
				obj.type = msg[index++];
				obj.owner_id = msg[index++];
				obj.map_x = msg[index++];
				obj.map_y = msg[index++];
				
				var char:ObjectCharPlayer = null;
				
				var arrayEquips:Array = new Array();
				if(obj.m_nImageId != 0)
				{
					arrayEquips.push(Engine.assetMapMonsterPath + "npc_"+ obj.m_nImageId + '.swf');
				}
				else
				{
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image0 + '.swf');
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image1 + '.swf');
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image2 + '.swf');
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image3 + '.swf');
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image4 + '.swf');
					arrayEquips.push(Engine.assetCharPath + "char_"+ obj.m_nRace+ obj.m_nGender + obj.equip_image5 + '.swf');
				}
				
				if(obj.m_nCharId == CharInfo.charId)//如果是自己才创建地图
				{
					PanelMain.getInstance().setBackgroundDecorator(null);
					if(!PanelMainHelp.getInstance().contains(SceneMain.getInstance()))
					{
						CharInfo.mapId = obj.map_id;
						//_sceneMain = new SceneMain(stage);
						SceneMain.getInstance().mouseEnabled = true;
						PanelMainHelp.getInstance().addChildAt(SceneMain.getInstance(),0);
						//PanelDate.getInstance().enterDate();
						//if(!this.isInBattle)
						//	FrameTrends.show();
						FrameChat.show();
						FrameBuff.show();
						FrameHomeMain.show();
						FrameInfoMain.show();
					}
					
					if(SceneMain.getInstance().map == null || SceneMain.getInstance().map.mapid != obj.map_id || obj.line_id != CharInfo.mapLineId
						|| obj.type != CharInfo.mapType || obj.owner_id != CharInfo.mapOwnerId)
					{
						FrameWorldMap.playJumpMap(CharInfo.mapId,obj.map_id);
						CharInfo.mapId = obj.map_id;
						CharInfo.mapLineId = obj.line_id;
						CharInfo.mapType = obj.type;
						CharInfo.mapOwnerId = obj.owner_id;
						SceneMain.getInstance().loadConfig('map'+obj.map_id);
						
						if(FrameHomeMain.isShowing())
							FrameHomeMain._frame.update();
						
						if(_timerMove != null && _timerMove.running)
						{
							_timerMove.stop();
						}
					}
					
					if(SceneMain.getInstance().focusObject != null)
					{
						SceneMain.getInstance().focusObject.moveTo(obj.map_x,obj.map_y);
					}
					
					CharInfo.mapLineId = obj.line_id;
					
					PanelMainHelp.getInstance().updateMapInfo();
					CharInfo.mapX = obj.map_x;
					CharInfo.mapY = obj.map_y;
					
					PanelMain.getInstance().showPanelMainHelp(true);
					FrameLogin.hide();
					FrameCreate.hide();
					FrameRegister.hide();
					
					char = SceneMain.getInstance().getObjectByCharId(obj.m_nCharId);
					if(char == null)
					{
						char = SceneMain.getInstance().createCharPlayer(arrayEquips,"char_"+ obj.image_id + '.swf',obj.m_szCharName,new Point(obj.map_x,obj.map_y),obj.m_nGender);
						CharInfo.objSelf = char;
						PanelMain.getInstance().setupListener();
					}
					CharInfo.objSelf.onMoveEnd = SceneMain.getInstance().onMoveEnd;
					CharInfo.objSelf.onMove = SceneMain.getInstance().onMove;
					CharInfo.objSelf.onMoveBegin = SceneMain.getInstance().onMoveBegin;
					char.charId = obj.m_nCharId;
					char.m_nRace = obj.m_nRace;
					char.m_nGender = obj.m_nGender;
					char.setLevel(obj.m_nLevel);
					char.userObject = obj;
					
					
					SceneMain.getInstance().addObject(char);
					SceneMain.getInstance().focusObject = char;
					CharInfo.objSelf = char;
					
					PanelMain.getInstance().updatePlayerMainImage();
					PanelMainHelp.getInstance().labelMapPosition.setText(CharInfo.mapX.toString()+","+CharInfo.mapY.toString());
				}
				else
				{
					char = SceneMain.getInstance().getObjectByCharId(obj.m_nCharId);
					if(char == null)
					{
						char = SceneMain.getInstance().createCharPlayer(arrayEquips,"char_"+ obj.image_id + '.swf',obj.m_szCharName,new Point(obj.map_x,obj.map_y),obj.m_nGender);
					}
					char.charId = obj.m_nCharId;
					char.m_nRace = obj.m_nRace;
					char.m_nGender = obj.m_nGender;
					char.setLevel(obj.m_nLevel);
					char.userObject = obj;
					char.load(arrayEquips,"char_"+ obj.image_id + '.swf');
				}
				
				char.setTitle(obj.title_name,0xeda61e,13);
				
				var mc_effect:MovieClip = null;
				if(obj.IsInBattle == 1)
				{
					mc_effect = Client.getEffectElement("mc_effect_" + SceneMain._effect_in_battle) as MovieClip;
					char.addEffect(SceneMain._effect_in_battle,mc_effect,true,false);
				}
				else
				{
					char.removeEffect(SceneMain._effect_in_battle);
				}
				
				if(obj.IsInMining== 1)
				{
					var effect_id:int = 5000000 + Math.random() % 6;
					mc_effect = Client.getEffectElement("mc_effect_" + effect_id) as MovieClip;
					char.addEffect(5000000,mc_effect,true,false);
				}
				else
				{
					char.removeEffect(5000000);
				}
			}
		}
		
		public static function phLeaveMap_7(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phLeaveMap_7", msg);
			
			SceneMain.getInstance().removeObject(SceneMain.getInstance().getObjectByCharId(msg[0]));
		}
		public static function phMove_8(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phMove_8", msg);
			var index:int = 0;
			var charId:int = msg[index++];
			var bMoveFromClient:int = msg[index++];
			var mapId:int = msg[index++];
			var lineId:int = msg[index++];
			var type:int = msg[index++];
			var owner_id:int = msg[index++];
			if(mapId != CharInfo.mapId)
				return;
			var obj:ObjectChar = SceneMain.getInstance().getObjectByCharId(charId) as ObjectChar;
			if(obj == null)
				return;
			
			var px:uint = msg[index++];
			var py:uint = msg[index++];
			
			if(SceneMain.getInstance().map == null) return;
			if(SceneMain.getInstance().map.AStar == null) return;
			// 得出路径
			if(charId == CharInfo.charId && bMoveFromClient == 1)
				return;
			if(charId == CharInfo.charId)
			{
				CharInfo.mapX = px;
				CharInfo.mapY = py;
			}
			obj.moveTo(px,py);
		}
		
		/**
		 * 通知服务器已发生了移动
		 * @param	p	移动坐标
		 */ 
		private static var _prevMoveTime	: int = 0;
		private static var _waitMove	: Boolean = false;
		public static var _timerMove:Timer = null;
		private static var _timerMoveCheckEnterBattle:Timer = null;
		//private var _mapX:int = 0;
		//private var _mapY:int = 0;
		public function onObjectMove(p:Point):void
		{
			if(p.x > CharInfo.objSelf.scene.map.mapWidth)
				return;
			if(p.y > CharInfo.objSelf.scene.map.mapHeight)
				return;
			
			CharInfo.objSelf.moveTo(p.x,p.y);
			
			if(_timerMove == null)
			{
				_timerMove = new Timer(1000);
				_timerMove.addEventListener(TimerEvent.TIMER,onTimerMove);
			}
			
			FrameClickMapChar.hide();
			Engine.Timer = getTimer();
			if(_prevMoveTime > Engine.Timer || Engine.Timer - _prevMoveTime > 1000)
			{
				onTimerMove(null);
			}
			else if(!_timerMove.running)
			{
				_timerMove.start();
			}
			
			CharInfo.mapX = p.x;
			CharInfo.mapY = p.y;
			PanelMainHelp.getInstance().labelMapPosition.setText(CharInfo.mapX.toString()+","+CharInfo.mapY.toString());
			clearNPCDialogTarget();
		}
		
		private function onTimerMove(e:TimerEvent):void
		{
			_timerMove.stop();
			Client.getInstance().sendPacketLogic(8,[CharInfo.mapId,CharInfo.mapLineId,CharInfo.mapType,CharInfo.mapOwnerId,CharInfo.mapX,CharInfo.mapY]);
			Engine.Timer = getTimer();
			_prevMoveTime = Engine.Timer;
			
			//if(PanelMainHelp.tmpNpcId != -1 && PanelMainHelp.tmpMapId != -1)
			//{
			//if(PanelMainHelp.tmpMapId == CharInfo.mapId)
			//{
			//	CharInfo.objSelf._targetNpcPos = new Point(PanelMainHelp.tmpMapX,PanelMainHelp.tmpMapY);
			//}
			//}
			
			//CharInfo.objSelf.moveTo(CharInfo.mapX,CharInfo.mapY);
			
		}
		
		private function onTimerMoveCheckEnterBattle(e:TimerEvent):void
		{
			if(PanelMain.getInstance().isInBattle)
				return;
			Client.getInstance().sendPacketLogic(25,[CharInfo.mapId,CharInfo.mapLineId,CharInfo.mapType,CharInfo.mapOwnerId,CharInfo.mapX,CharInfo.mapY]);
		}
		
		public function onMoveBegin(target_x:int,target_y:int):void
		{
			trace("onMoveBegin");
			if(_timerMoveCheckEnterBattle == null)
			{
				_timerMoveCheckEnterBattle = new Timer(8000);
				_timerMoveCheckEnterBattle.addEventListener(TimerEvent.TIMER,onTimerMoveCheckEnterBattle);
			}
			
			if(!_timerMoveCheckEnterBattle.running)
			{
				_timerMoveCheckEnterBattle.reset();
				_timerMoveCheckEnterBattle.delay = Engine.Timer % 4000 + 4000;
				_timerMoveCheckEnterBattle.start();
			}
			
			if(SceneMain.getInstance().objectClick != null)
			{
				SceneMain.getInstance().objectClick._frameCurrent = 0;
				SceneMain.getInstance().objectClick.setPos(target_x,target_y);
				SceneMain.getInstance().objectClick.visible = true;
			}
		}
		public function onMove():void
		{
			PanelMainHelp.getInstance().updateMapInfo();
		}
		public function onMoveEnd():void
		{
			trace("onMoveEnd");
			checkNPCDialogTarget();
			if(_timerMove != null && _timerMove.running)
				_timerMove.stop();
			//Client.getInstance().sendPacketLogic(25,[CharInfo.mapId,CharInfo.mapLineId,CharInfo.mapType,CharInfo.mapOwnerId,CharInfo.mapX,CharInfo.mapY]);
			
			if(_timerMoveCheckEnterBattle != null && _timerMoveCheckEnterBattle.running)
			{
				_timerMoveCheckEnterBattle.stop();
			}
			
			if(SceneMain.getInstance().objectClick != null)
			{
				SceneMain.getInstance().objectClick.visible = false;
			}
		}
		
		public function clearNPCDialogTarget():void
		{
			PanelMainHelp.tmpNpcId = -1;
			PanelMainHelp.tmpMapId = -1;
			PanelMainHelp.tmpMapX = 0;
			PanelMainHelp.tmpMapY = 0;
		}
		public function checkNPCDialogTarget():void
		{
			if(PanelMain.getInstance().isInBattle)
				return;
			if(PanelMainHelp.tmpNpcId != -1 && PanelMainHelp.tmpMapId != -1)
			{
				var npc:ObjectCharNPC = SceneMain.getInstance().getObjectByNpcId(PanelMainHelp.tmpNpcId);
				if(npc == null)
					return;
				
				if(Point.distance(npc.getPos(),CharInfo.objSelf.getPos()) > 100)
				{
					//CharInfo.objSelf._targetNpcPos = npc.getPos();//new Point(int(npc.getPos().x),int(npc.getPos().y));
					Client.getInstance().sendPacketLogic(9,[int(PanelMainHelp.tmpMapId),CharInfo.mapLineId,int(0),int(0),int(npc.getPos().x),int(npc.getPos().y)]);
					return;
				}
				
				FrameNPCDialog._currentCharNpc = npc;
				if(FrameNPCDialog._currentCharNpc != null)
				{
					Client.getInstance().sendPacketLogic(900,[int(PanelMainHelp.tmpNpcId)]);
					//trace("onMoveEnd");
				}
				PanelMainHelp.tmpNpcId = -1;
				PanelMainHelp.tmpMapId = -1;
				PanelMainHelp.tmpMapX = 0;
				PanelMainHelp.tmpMapY = 0;
				//trace("onMoveEnd1");
			}
			//trace("onMoveEnd2,PanelMainHelp.tmpNpcId:"+PanelMainHelp.tmpNpcId+'PanelMainHelp.tmpMapId:'+PanelMainHelp.tmpMapId+'PanelMainHelp.tmpMapX:'+PanelMainHelp.tmpMapX);
			//trace("onMoveEnd2");
		}
		
		public static function phNPC_2200(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phNPC_2200", msg);
			var index:int = 0;
			var nMapId:int = msg[index++];
			var nLineId:int = msg[index++];
			var nType:int = msg[index++];
			var nOwnerId:int = msg[index++];
			
			var count:int = msg[index++];
			for(var i:int = 0; i != count; i++)
			{
				var obj:Object = new Object();
				obj.m_nCSVId = msg[index++];
				obj.m_nOwnerCharId = msg[index++];
				obj.m_strTitle = msg[index++];
				obj.m_strName = msg[index++];
				obj.m_nImageId = msg[index++];
				obj.m_nMapId = msg[index++];
				obj.m_nMapX = msg[index++];
				obj.m_nMapY = msg[index++];
				
				var objChar:ObjectCharNPC = SceneMain.getInstance().createCharNPC(Engine.assetMapNpcPath + "npc_"+ obj.m_nImageId + '.swf',"npc_"+ obj.m_nImageId + '.swf',obj.m_strName,new Point(obj.m_nMapX,obj.m_nMapY));
				objChar.npcId = obj.m_nCSVId;
				objChar.setTitle(obj.m_strTitle);
				objChar.userObject = {npc_id:obj.m_nCSVId,npc_name:obj.m_strName};
			}
		}
		
		public static function phUpdateNPC_2201(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phUpdateNPC_2201", msg);
			var index:int = 0;
			var nMapId:int = msg[index++];
			var nLineId:int = msg[index++];
			var nType:int = msg[index++];
			var nOwnerId:int = msg[index++];
			var bAdd:int = msg[index++];
			if(bAdd == 1)
			{
				var obj:Object = new Object();
				obj.m_nCSVId = msg[index++];
				obj.m_nOwnerCharId = msg[index++];
				obj.m_strTitle = msg[index++];
				obj.m_strName = msg[index++];
				obj.m_nImageId = msg[index++];
				obj.m_nMapId = msg[index++];
				obj.m_nMapX = msg[index++];
				obj.m_nMapY = msg[index++];
				
				var objChar:ObjectCharNPC = SceneMain.getInstance().createCharNPC(Engine.assetMapNpcPath + "npc_"+ obj.m_nImageId + '.swf',"npc_"+ obj.m_nImageId + '.swf',obj.m_strName,new Point(obj.m_nMapX,obj.m_nMapY));
				objChar.npcId = obj.m_nCSVId;
				objChar.setTitle(obj.m_strTitle);
				objChar.userObject = {npc_id:obj.m_nCSVId,npc_name:obj.m_strName};
			}
			else
			{
				
			}
		}
	}
}